package com.vlin.mapper.device;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.vlin.entity.device.Device;

public interface DeviceMapper {

	@Insert("insert into device (cid,did,disabled,fid,ip,mode,name,online,parent,pid,puid,rid,time_zone,token,uid,category) "
			+ "values(#{cid},#{did},#{disabled},#{fid},#{ip},#{mode},#{name},#{online},#{parent},#{pid},#{puid},#{rid},#{time_zone},#{token},#{uid},#{category})")
	public int insert(Device device);
	
	@Update("update device set "
			+ "cid=#{cid},"
			+ "did=#{did},"
			+ "disabled=#{disabled},"
			+ "fid=#{fid},"
			+ "ip=#{ip},"
			+ "mode=#{mode},"
			+ "name=#{name},"
			+ "online=#{online},"
			+ "parent=#{parent},"
			+ "pid=#{pid},"
			+ "puid=#{puid},"
			+ "rid=#{rid},"
			+ "time_zone=#{time_zone},"
			+ "token=#{token},"
			+ "category=#{category},"
			//+ "create=#{create,jdbcType=DATE},"
			+ "uid=#{uid} where did=#{did}")
	public int update(Device device);
	
	
	@Select("select devid from device where did=#{did}")
	public String findDevId(@Param("did")String did);
	
	@Select("select * from device where uid = uid")
	public List<Device> findDevByUid(@Param("uid")int uid);
	
	@Update("update device set online=#{online} where did=#{did} ")
	public int updateOnlineByDid(@Param("did") String did, @Param("online") int online);
	
	@Update("update device set disabled=#{disabled} where did=#{did}")
	public int updateDisabledByDid(@Param("did") String did, @Param("disabled") int disabled);
	
	@Update("update device set name=#{name} where did=#{did}")
	public int updateNameByDid(@Param("did") String did, @Param("name") String name);
	
}
